<?php

namespace app\admin\model;

use think\Model;


//维修明细
class TasksService extends Model
{
    // 表名
    protected $table = 'tasks_service';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    // 追加属性
    protected $append = [
        'images_arr',
        'createtime_text'
    ];

    public function getImagesArrAttr($value,$data)
    {
        $value = $value ? $value : (isset($data['images']) ? $data['images'] : '');
        return !$value ? [] : explode(',', $value);
    }

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    //获取任务维修明细
    public static function getTasksService($taskId)
    {
        return self::where('task_id',$taskId)->order('createtime desc')->select();
    }

    //指定用户指定任务的记录
    public static function getTaksLogs($user_id,$task_id)
    {
        return self::where('user_id',$user_id)->where('task_id',$task_id)->where(['total_fee'=>['>',0]])->order('createtime desc')->select();
    }

    //任务维修item
    public static function getItem($task_id)
    {
        $data = self::where('task_id',$task_id)->order('createtime desc')->select();
        $result = [];
        foreach ($data as $list){
            $result[] = $list['user_nickname'].':'.$list['art_name'].'*'.$list['num'];
        }
        return $result;
    }

}
